package Arrays;

public class _167_TwoSumIIInputarrayissorted {
    public int[] twoSum(int[] numbers, int target) {
        int[] result = new int[2];
        int length = numbers.length;
        for(int i=0;i<length;i++){
            int sub = target - numbers[i];
            for(int j=i+1;j<length;j++){
                if(sub==numbers[j]){
                    result[0] = i+1;
                    result[1] = j+1;
                    return result;
                }
            }
        }
        return result;
    }
    public int[] twoSum1(int[] numbers, int target){
        int left = 0,right = numbers.length-1;
        while(left!=right){
            int sum = numbers[left] + numbers[right];
            if(sum==target){
                return new int[]{left+1,right+1};
            }else if(sum<target){
                left++;
            }else{
                right--;
            }
        }
        return new int[]{};
    }
}
